package com.net.xpay.web.controller.merchant;

import com.net.xpay.web.vo.UserTransStatVo;
import com.net.common.model.ResultPagedList;
import com.net.xpay.common.domain.User;
import com.net.xpay.common.domain.stat.UserTransStat;
import com.net.xpay.common.manager.stat.UserTransStatManager;
import com.net.xpay.core.model.UserTransStatSearchModel;
import com.net.xpay.core.utils.BeanCopierUtil;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 用户安全付转账统计
 **/
@RestController
@RequestMapping("/merchant/user-trans-stat")
@Api(tags = "商户/用户批量有密转账统计", description = "用户批量有密转账统计")
public class UserTransStatController {

    @Autowired
    private UserTransStatManager userTransStatManager;

    @ApiOperation(value = "用户批量有密转账统计")
    @PostMapping(value = "/search")
    public ResultPagedList<UserTransStatVo> search(@ApiIgnore @RequestUser User merchant, @RequestBody UserTransStatSearchModel searchModel) {
        searchModel.setUserId(merchant.getId());
        // 根据查询条件进行查询
        List<UserTransStat> userTransStatList = userTransStatManager.search(searchModel);
        // 查询带条件后数据的条数
        long count = userTransStatManager.searchCount(searchModel);

        List<UserTransStatVo> vos = BeanCopierUtil.batchCopy(UserTransStat.class, UserTransStatVo.class, userTransStatList);
        return new ResultPagedList<>(vos, count, searchModel);
    }
}